<%include ../common/include_header1.html%>

<div class="cont">
  <%include menu.html%>
  <div class="right">
    <div class="huisheng-success-wrap clearfix">
                <div class="huisheng-success" style="background: url(/web/images/success.jpg) no-repeat;"></div>
              </div>
    <div class="lj">
      <a href="/index.html"><img src="/web/images/tb6.png"></a> |
      <a href="#"></a>
      <a href="/index.html">首页</a>&gt;
      <a href="/company_dynamic/dynamic">企业动态</a> &gt;
      <a href="javascript:void(0)" id="mtitle"></a>
      <!-- <a href="#">企业简介</a> -->
    </div>
    <div class="right_nr">
      <div class="tw_ls">
        <ul></ul>
      </div>
      <div class="wz-ls">
        <ul></ul>
      </div>
      <div class="admin-table-page">
        <div id="page" class="page">
        </div>
      </div>
    </div>
  </div>
  <div class="clear"></div>
  <style type="text/css">
    .page {
      text-align: center;
      font-size: 14px;
      margin: 40px 30px;
    }
    
    .page a {
      color: #000;
      border: 1px solid #ededed;
      background: #fbfcfb;
      padding: 5px 10px;
      margin-left: 4px;
    }
    
    .page a:hover {
      color: #f00000;
    }
    
    .layui-laypage-curr {
      color: #000;
      border: 1px solid #ededed;
      background: #fbfcfb;
      padding: 5px 10px;
    }
    
    .layui-laypage-curr em {
      font-style: normal;
    }
    
    .layui-laypage-curr em:hover {
      color: #f00000;
    }
  </style>
</div>
<script type="text/javascript" src="/web/layui/layui.js"></script>
<script>
  //一般直接写在一个js文件中
  layui.use(['layer', 'laypage', 'form'], function() {
    var layer = layui.layer,
      laypage = layui.laypage,
      $ = layui.jquery;
    var value = "<%=value%>";
    //页面初始化的时候执行
    $(function() {
      $("#news").addClass("active");
      //第一个参数：多少页，第二个参数，新闻类型，0企业动态，1媒体报道，2活动报道

      switch(value) {
        case 'dynamic':
          getData(1, 0);
          $("#mtitle").text("企业新闻")
          break;
        case 'media':
          getData(1, 1);
          $("#mtitle").text("媒体关注")
          break;
        case 'activity':
          getData(1, 2);
          $("#mtitle").text("企业活动")
          break;
        case 'announcement':
          getData(1, 3);
          $("#mtitle").text("通告公告")
          break;

      }

    });

    //从后台获取数据函数，获取页数curr的数据
    function getData(curr, category) {

      $.post("/web/get_news_by_Category1", {
        curr: curr,
        category: category
      }, function(result) {
        //拼接html内容
        var tabContent = "";
        //获取后台json数据
        var mydata = result.data;
        console.log(mydata)
        if("<%= value %>" != "announcement") {

          for(var i = 0; i < mydata.length; i++) {
            var content = mydata[i].content
            var title = mydata[i].title;
            title = title.slice(0, 50);
            var imgReg = /<img.*?(?:>|\/>)/gi;
            //匹配src属性 
            var srcReg = /src=[\'\"]?([^\'\"]*)[\'\"]?/i;
            var arr = content.match(imgReg);

            if(arr) {
              var src = arr[0].match(srcReg);
              mydata[i].img = src[1].toString();
            } else {
              mydata[i].img = '/web/images/noimg.jpg';
            }
            var content = mydata[i].content;
            //			        	content=content.match(/<p>(.+)<\/p>/)[1];
            content = content.replace(/<[^>]+>/g, ""); //去掉所有的html标记
            if(content.length > 150) {
              content = content.slice(0, 150) + '...'
            }

            var tempStr = '<li><a href="/news_detail1/' + mydata[i]._id + '" title="' + title + '">' +
              '<div class="tw_img"><div class="jqthumb" style="width: 113px; height: 86px;"><div style="width: 100%; height: 100%;' +
              ' background-image: url(&quot;/' + mydata[i].img + '&quot;); background-repeat: no-repeat; background-position: 50% 50%; background-size: cover;"></div></div><img src="/' + mydata[i].img + '" style="display: none;"></div>' +
              '<div class="tw_nr"><div class="ra">' + title + '<span>' + mydata[i].time + '</span></div>' +
              '<p>' + content + '</p></div></a></li>'
            tabContent += tempStr;
            //                  var tempStr='<tr id='+mydata[i]._id+'>'+
            //                              /*序号分页后也必须得变动,每页十条数据*/
            //                          '<td>'+(i+(curr-1)*10+1)+'、 <a href="/news_detail/'+mydata[i]._id+'" class="a_color">'+mydata[i].title+'</a><span class="pull-right">'+mydata[i].time+'</span></td>'+
            //                          '</tr>'

          }
           //将拼接好的数据填入#tabContent中
          $(".tw_ls ul").eq(0).html(tabContent);
        } else {
            
            for(var i = 0; i < mydata.length; i++) {
              var title = mydata[i].title;
            var time = mydata[i].time;
            time=time.split(" ")
            time=time[0]
          var tempStr ='<li><a href="/news_detail1/' + mydata[i]._id + '"><span>['+time+']</span>'+title+'</a></li>'
          tabContent += tempStr;
          }
            $(".wz-ls ul").eq(0).html(tabContent);
        }
       

        
        //显示分页
        laypage({
          cont: 'page', //容器。值支持id名、原生dom对象，jquery对象。【如该容器为】：<div id="page1"></div>
          pages: result.pages, //通过后台拿到的总页数
          curr: curr || 1, //当前页
          skin: '#c52d2f',
          layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip'],
          jump: function(obj, first) { //触发分页后的回调
            if(!first) { //点击跳页触发函数自身，并传递当前页：obj.curr
              switch(value) {
                case 'dynamic':
                  getData(obj.curr, 0);
                  break;
                case 'media':
                  getData(obj.curr, 1);
                  break;
                case 'activity':
                  getData(obj.curr, 2);
                  break;
                case 'announcement':
                  getData(obj.curr, 3);
                  break;

              }
            }
          }
        });

      });
    };
  });
</script>
<%include ../common/include_footer1.html%>